﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using log4net;
using log4net.Config;
using DTO;
using AutoMapper;

namespace DataAccess
{
    public static class RankingPriorityDAO
    {
        private static readonly ILog logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
        static RankingPriorityDAO()
        {
            XmlConfigurator.Configure();
        }

        public static RankingPriorityDTO GetRankingPriority()
        {
            try
            {
                QUANLYBONGDA_VDQG_1042102Entities context = new QUANLYBONGDA_VDQG_1042102Entities();
                var query = from r in context.RANKING_PRIORITY_LIST
                            select r;
                RankingPriorityDTO Result = new RankingPriorityDTO();
                RANKING_PRIORITY rank = query.First();
                Result = Mapper.Map<RANKING_PRIORITY, RankingPriorityDTO>(rank);
                return Result;
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return null;
            }
        }

        public static bool UpdateRankingPriority(RankingPriorityDTO dtoRankingPriority)
        {
            try
            {
                QUANLYBONGDA_VDQG_1042102Entities context = new QUANLYBONGDA_VDQG_1042102Entities();

                RANKING_PRIORITY obj = (from r in context.RANKING_PRIORITY_LIST
                                        select r).First();
                obj.RANKING_BY_GOALDIFFERENCE = dtoRankingPriority.RANKING_BY_GOALDIFFERENCE;
                obj.RANKING_BY_GOALFOR  = dtoRankingPriority.RANKING_BY_GOALFOR ;
                obj.RANKING_BY_ONEONONE  = dtoRankingPriority.RANKING_BY_ONEONONE ;
                obj.RANKING_BY_SCORES  = dtoRankingPriority.RANKING_BY_SCORES ;               


                context.SaveChanges(true);
                return true;
            }
            catch (Exception ex)
            {
                logger.Error(ex);
                return false;
            }
        }
    }
}
